import { MUI_APP_VISIT_INFO } from '../../_constant'

const enterPageTime = Symbol('muiEnterPageTime')
export default {
  data() {
    return {
      [enterPageTime]: 0
    }
  },
  onLoad() {
    uni.$PAGE_PATH = this.route || this.__route__
  },
  onShow() {
    this[enterPageTime] = +new Date()
  },
  onHide() {
    this.muiViewPageTime()
  },
  onUnload() {
    this.muiViewPageTime()
  },
  methods: {
    muiViewPageTime() {
      const diffViewTime = +new Date() - this[enterPageTime]

      uni.$emit(MUI_APP_VISIT_INFO, {
        params: this.options,
        vt: diffViewTime,
        et: +new Date()
      })
    }
  }
}
